<template>
<div>
  <h1>用reduce判断字符串出现的频率</h1>
  <button @click="doit">用reduce判断字符串出现的频率</button>
</div>
</template>

<script>
export default {
  // name: '',
  components: {},
  data () {
    return {
      result:0
    }
  },
  created () { },
  mounted () { },
  methods: {
   countCharacters(str) {
  return str.split('').reduce((acc, char)=> {
    if (acc[char]) {
      console.log(acc, char);
      console.log(acc[char]);
      acc[char]++;
    } else {
      console.log(acc[char]);
      acc[char] = 1;
    }
    return acc;
  }, {});
}
,
doit(){
this.result = this.countCharacters('Hello, world!')
return console.log(this.result);
}
},
  computed: {}
}
</script>
<style scoped lang='scss'>

</style>
